In [20]:
text = (
"HeL, lo Mom, "
"Im, sO, rRYi, dIDn, t, Wri, Teto, YoUS, O, oN, eRif, ee, "
"Lter, rI, Bl, E, ABO, uTr, U, nnI, nGa, w, Ay, BUT, iwAn, "
"TYO, UTO, Kno, W, that, i MfIN, eIM, co, mIng, hOme, SoO, "
"ni, lOve, yOus, OM, u, chic, a, nTwa, iTTo, seey, o, uImo, "
"kLOv, eyou, m, oMby, eBYe"
)
Define the morse code
In [12]:
ALPHA_MORSE = {
'A': '.-', 'B': '-...', 'C': '-.-.',
'D': '-..', 'E': '.', 'F': '..-.',
'G': '--.', 'H': '....', 'I': '..',
'J': '.---', 'K': '-.-', 'L': '.-..',
'M': '--', 'N': '-.', 'O': '---',
'P': '.--.', 'Q': '--.-', 'R': '.-.',
'S': '...', 'T': '-', 'U': '..-',
'V': '...-', 'W': '.--', 'X': '-..-',
'Y': '-.--', 'Z': '--..',
'0': '-----', '1': '.----', '2': '..---',
'3': '...--', '4': '....-', '5': '.....',
'6': '-....', '7': '--...', '8': '---..',
'9': '----.'
}
In [13]:
MORSE_ALPHA = {v:k for k,v in ALPHA_MORSE.iteritems()}; MORSE_ALPHA
Out[13]:
Create a function to easily modify our "guesses" of what the translation scheme is
In [46]:
def trans(c):
if c.isupper():
return '-'
elif c.islower():
return '.'
else:
return ' '
In [47]:
translated_text = ''.join(map(trans, text)); translated_text
Out[47]:
Now we translate from morse
In [48]:
''.join(map(lambda c: MORSE_ALPHA.get(c, '?'), translated_text.split()))
Out[48]:
Shit got real, yo